extends PlayerState
class_name PlayerStateHeader

const BALL_HEIGHT_MIN := 8
const BALL_HEIGHT_MAX := 30
const BOUNS_POWER := 1.3
const HEIGHT_START := 0.5
const HEIGHT_VELOCITY := 1.5

func _enter_tree() -> void:
	animation_player.play("header")
	player.height = HEIGHT_START
	player.height_velocity = HEIGHT_VELOCITY
	ball_detection_area.body_entered.connect(on_ball_entered.bind())

func on_ball_entered(contact_ball : Ball) -> void:
	if ball.can_air_connect(BALL_HEIGHT_MIN, BALL_HEIGHT_MAX):
		contact_ball.shoot(player.velocity.normalized() * player.power* BOUNS_POWER )

func _process(_delta: float) -> void:
	if player.height == 0:
		transition_state(Player.State.RECOVERING)
